﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace AppKey {
  public partial class FormProgress :Form {
    public FormProgress() {
      InitializeComponent();
    }
    public void setTotalProgressMaximun(int maximun) {
      progressBarX1.Maximum = maximun;
    }
    public int getTotalProgressMaximun() {
      return progressBarX1.Maximum;
    }
    /// <summary>
    /// 安装总进度
    /// </summary>
    /// <param name="nValue"></param>
    /// <returns></returns>
    public bool IncreaseTotal(int nValue) {
      if( nValue > 0 ) {
        if( progressBarX2.Value + nValue < progressBarX2.Maximum ) {
          progressBarX2.Value += nValue;
          
          return true;
        } else {
          progressBarX2.Value = progressBarX2.Maximum;
          this.Close();
          return false;
        }
      }
      return false;
    }
    /// <summary>
    /// 当前安装进度条
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public bool increaceCurrent(int value) {
      if(value >0){
        if( progressBarX1.Value + value < progressBarX1.Maximum ) {
          progressBarX1.Value += value;
          return true;
        } else {
          //this.Close();
          return false;
        }
      }
      return false;
    }
    private void progressBarX1_Click(object sender, EventArgs e) {

    }

    private void FormProgress_Load(object sender, EventArgs e) {

    }
    public void progressCurrent(){
      Thread thread = new Thread(new ThreadStart(thredFun));
      thread.Start();
    }
    private void thredFun() {
      //Thread.Sleep(1000);
      do{
        Thread.Sleep(1);
        increaceCurrent(1);
      }while(progressBarX2.Value>=progressBarX2.Maximum);
    }

    public void setLable(String str) {
      labelX1.Text = str;
    }
  }
}
